/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 * New group page that user creates
 * User need to enter name, description
 * session.userID
 * @author Kyu
 */
public class GroupNewServlet extends HttpServlet {
   
    String userID = "Karl";
      
    
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
         
            out.println("<html>");
            out.println("<head>");
            
            generateInlineJS(out);
            CSSGenerator.generateNewsGroupMainPageInlineCSS(out);
            out.println("<title>Servlet GroupNewServlet</title>");  
            out.println("</head>");
            out.println("<body>");
            //out.println("<h1>Servlet GroupNewServlet at " + request.getContextPath () + "</h1>");
              out.println(
                    "<form name=\"wall\" action = \"GroupNewServlet\" method=\"post\">" +
                    
                        "<center>" +
                        "<br>Create New Group</br>" +
                        "<Table width=\"40%\" border>" +                        
                        //"   <tr>" + 
                        //"   <th> Create New Group </th>" + 
                        //"   </tr>" +
                        /* second row: Group name textbox */
                        "   <tr><br>"+                            
                        "     Group Name: " +
                        "     <input type=\"text\" name=\"GroupName\" size=\"20\" >" +  
                        "    </br></tr>" +
                        /* thrid row: Enter the description of the group */       
                        "    <tr>" +
                        "     Description: " +
                        "     <TEXTAREA wrap=\"virtual\" name=\"Description\" cols = 50 rows=4></textarea>" +                                                              
                        "    </tr>" + 
                        /* 4th row: create the group button */     
                       
                         "  <input type=\"submit\" value=\"New\" name=\"newGroup\">" +
                        "    </tr>"+
                        "   </table>" +      
                        "</form>"); 
            
            out.println("</body>");
            out.println("</html>");
           
        } finally { 
            out.close();
        }
    } 
private void generateInlineJS(PrintWriter out)
    {
        out.println(
                 "<script language=\"javascript\"> " +
         "function loadwindow(target)" +
         "{" +
         "       window.open(target,\"\",\"width=800,height=600,status=1,menubar=0,resizable=1\");" +      
         "}" +
         "</script>"
       );
    }
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println(userID);
        out.println(request.getParameter("GroupName"));
        out.printf(request.getParameter("Description"));
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
